package com.css.zfzx.sjcj.modules.statistics.fxqhHddc200.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.bpm.platform.utils.PlatformPageUtils;
import com.css.zfzx.sjcj.common.utils.ServerUtil;
import com.css.zfzx.sjcj.modules.pojo.QueryVo;
import com.css.zfzx.sjcj.modules.statistics.fxqhHddc100.service.FxqhHddc100Service;
import com.css.zfzx.sjcj.modules.statistics.fxqhHddc200.service.FxqhHddc200Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/pc/fxqhHddc200")
public class FxqhHdc200Controller {
    @Autowired
    FxqhHddc200Service service;
    ///pc/fxqhHddc200/findData
    @GetMapping("/findData")
    public RestResponse findData(QueryVo queryVo, HttpServletRequest req) {
        RestResponse response = null;
        String userId = ServerUtil.getUserId(req);
        try{
            int curPage = Integer.valueOf(req.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(req.getParameter(PlatformPageUtils.PAGE_SIZE));
            String sort= req.getParameter("sort");
            String order= req.getParameter("order");
            JSONObject list = service.find(queryVo,userId,curPage,pageSize,sort,order);
            response = RestResponse.succeed(list);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    @GetMapping("/export")
    public void export(HttpServletRequest req, HttpServletResponse resp) {
        String userId = ServerUtil.getUserId(req);
        service.export(userId,resp);
    }

    /***
     * 系统自动质检
     * @param queryVo
     * @return
     */
    @PostMapping("/dataQualityCheck")
    public RestResponse dataQualityCheck(@RequestBody QueryVo queryVo) {
        RestResponse responseRest = null;
        JSONObject jsonObject = new JSONObject();
        try{
            service.dataQualityCheck(queryVo);
            jsonObject.put("message", "质检成功！");
            responseRest = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "质检失败!";
            responseRest = RestResponse.fail(errorMessage);
        }
        return responseRest;
    }
}
